(function ($) {
  //added by xiaobei 2020/07/09， 解决火狐拖拽新开窗口问题。
  document.body.ondrop = function (event) {
    event.preventDefault();
    event.stopPropagation();
  }
  //added by xiaobei 2020/07/02， 解决ie不兼容endsWith的问题。
  String.prototype.endsWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
      return false;
    if (this.substring(this.length - str.length) == str)
      return true;
    else
      return false;
    return true;
  }
  //xiaobei end
  //added by lmc 2021-05-13， 解决ie不兼容startsWith的问题。
  String.prototype.startsWith=function(str){
  if(str==null||str==""||this.length==0||str.length>this.length)
    return false;
  if(this.substr(0,str.length)==str)
    return true;
  else
    return false;
  return true;
  }
  //add end

  String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, ""); //正则匹配空格
  }

  if (!Array.indexOf) {
    Array.prototype.indexOf = function (obj) {
      for (var i = 0; i < this.length; i++) {
        if (this[i] == obj) {
          return i;
        }
      }
      return -1;
    }
  }

  //added by xiaobei 2020/07/28， 解决ie8不兼容filter和foreach的问题。
  if (!Array.prototype.filter) {
    Array.prototype.filter = function (fun /*, thisArg */) {
      "use strict";

      if (this === void 0 || this === null)
        throw new TypeError();

      var t = Object(this);
      var len = t.length >>> 0;
      if (typeof fun !== "function")
        throw new TypeError();

      var res = [];
      var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
      for (var i = 0; i < len; i++) {
        if (i in t) {
          var val = t[i];
          if (fun.call(thisArg, val, i, t))
            res.push(val);
        }
      }

      return res;
    };
  }

  if (!Array.prototype.forEach) {

    Array.prototype.forEach = function forEach(callback, thisArg) {

      var T, k;

      if (this == null) {
        throw new TypeError("this is null or not defined");
      }
      var O = Object(this);
      var len = O.length >>> 0;
      if (typeof callback !== "function") {
        throw new TypeError(callback + " is not a function");
      }
      if (arguments.length > 1) {
        T = thisArg;
      }
      k = 0;

      while (k < len) {

        var kValue;
        if (k in O) {

          kValue = O[k];
          callback.call(T, kValue, k, O);
        }
        k++;
      }
    };
  }
  //xiaobei end

  //ie不兼容Object.assign
  if (typeof Object.assign != 'function') {
    Object.assign = function(target) {
      'use strict';
      if (target == null) {
        throw new TypeError('Cannot convert undefined or null to object');
      }

      target = Object(target);
      for (var index = 1; index < arguments.length; index++) {
        var source = arguments[index];
        if (source != null) {
          for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }
      }
      return target;
    };
  }


  placeholderRender()

  //兼容ie8不支持Object.keys
  var DONT_ENUM = "propertyIsEnumerable,isPrototypeOf,hasOwnProperty,toLocaleString,toString,valueOf,constructor".split(","),
    hasOwn = ({}).hasOwnProperty;
  for (var i in {
    toString: 1
  }) {
    DONT_ENUM = false;
  }


  Object.keys = Object.keys || function (obj) {//ecma262v5 15.2.3.14
    var result = [];
    for (var key in obj) if (hasOwn.call(obj, key)) {
      result.push(key);
    }
    if (DONT_ENUM && obj) {
      for (var i = 0; key = DONT_ENUM[i++];) {
        if (hasOwn.call(obj, key)) {
          result.push(key);
        }
      }
    }
    return result;
  };


  //兼容ie8不支持Object.keys end
  //兼容ie8不支持map
  if (typeof Array.prototype.map != "function") {
    Array.prototype.map = function (fn, context) {
      var arr = [];
      if (typeof fn === "function") {
        for (var k = 0, length = this.length; k < length; k++) {
          arr.push(fn.call(context, this[k], k, this));
        }
      }
      return arr;
    };
  }
  //兼容ie8不支持map end

  if (typeof Array.prototype.reduce != "function") {
    Array.prototype.reduce = function (callback, initialValue) {
      var previous = initialValue, k = 0, length = this.length;
      if (typeof initialValue === "undefined") {
        previous = this[0];
        k = 1;
      }

      if (typeof callback === "function") {
        for (k; k < length; k++) {
          this.hasOwnProperty(k) && (previous = callback(previous, this[k], k, this));
        }
      }
      return previous;
    };
  }

  //兼容ie8不支持Object.values
  Object.values = Object.values || function (obj) {
    var result = [];
    Object.keys(obj).map(function(e) {
      result.push(obj[e])
    })
    return result
  }

})(jQuery);

function placeholderSupport() {
  return 'placeholder' in document.createElement('input');
}

function placeholderRender() {
  //兼容ie9不支持placeholder标签
  if (!placeholderSupport()) {   // 判断浏览器是否支持 placeholder
    function GetStringNumValue(pxstr) {
      return pxstr.substring(0, pxstr.length - 2);
    }

    if ($('input[placeholder],textarea[placeholder]').parents('#formBuild-ie8').length) {
      return false;
    }
    $('input[placeholder],textarea[placeholder]').each(function () {
      var $element = $(this),
        placeholder = $element.attr('placeholder');

      if (placeholder) {
        // 文本框ID
        var elementId = $element.attr('id');
        if (!elementId) {
          var now = new Date();
          elementId = 'lbl_placeholder' + now.getSeconds() + now.getMilliseconds();
          $element.attr('id', elementId);
        }
      }//end of if (placeholder)
       // 添加label标签，用于显示placeholder的值
      var $label = $('<label>', {
        html: $element.val() ? '' : placeholder,
        'for': elementId,
        css: {
          position: 'absolute',
//									float: 'left',
          cursor: 'text',
          color: '#ccc',
          fontSize: $element.css('fontSize'),
          fontFamily: $element.css('fontFamily'),
          zIndex: 9,
        }
      }).insertAfter($element);
      // 绑定事件
      $label.addClass('ie-placeholder')
      var _setPosition = function () {
        $label.css({
//							marginTop:'-27px',
//							marginLeft:'15px',
          top: '7px',
          left: '30px',
        });
      };
      var _resetPlaceholder = function () {
        if ($element.val()) {
          $label.html(null);
        } else {
          _setPosition();
          $label.html(placeholder);
        }
      };
      _setPosition();
      $element.on('focus blur input keyup propertychange resetplaceholder', _resetPlaceholder);

      if (isIE9 && $element.attr('readonly')){
        $element.click(function(){
          var intervalName;
          intervalName = setInterval(function () {
            console.log('ie9的propertychange在失去焦点后不会触发，使用定时器来绑定了此方法！如果认为此方式耗性能，建议不要给该项添加placeholder属性')
            $element.trigger("propertychange");
            if ($element.val()){
              clearInterval(intervalName);
            }else{
            }
          },1000);
        });
      }


    });


  }
}